//package com.sky.task;
//
//import com.sky.constant.StatusConstant;
//import com.sky.entity.Orders;
//import com.sky.mapper.UserMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.util.List;
//
//@Component
//@Slf4j
//public class OrderTask {
//    @Autowired
//    private UserMapper userMapper;
//    @Scheduled(cron="0 0/1 * * * ? ")
//    public void processTimeout()
//    {
//        log.info("定时处理超时订单{}", LocalDateTime.now());
//        LocalDateTime  time= LocalDateTime.now().minusMinutes(1);
//        //查询过期订单
//        List<Orders> timeoutorders = userMapper.selectbytimeoutorder(StatusConstant.ENABLE, time);
//        //批量更改订单状态和取消原因
//        if(timeoutorders!=null && timeoutorders.size()>0);
//        for (Orders timeoutorder : timeoutorders) {
//            timeoutorder.setStatus(Orders.CANCELLED);
//            timeoutorder.setCancelReason("订单超时");
//            timeoutorder.setCancelTime(LocalDateTime.now());
//            userMapper.update(timeoutorder);
//        }
//    }
//
//    @Scheduled(cron="0 0 1 * * ? ")
//    public void processDeliverOrder()
//    {
//        log.info("定时处理派送中的订单{}", LocalDateTime.now());
//        List<Orders> orders = userMapper.selectDeliverOrder(Orders.DELIVERY_IN_PROGRESS);
//        for (Orders order : orders) {
//            order.setStatus(Orders.COMPLETED);
//            userMapper.update(order);
//        }
//    }
//}
